<template>
  <div class="home-container">
    <el-container>
      <!-- 顶部导航 -->
      <el-header class="header">
        <div class="logo">动态字段管理系统</div>
        <div class="user-info">
          <el-avatar icon="User" size="small"></el-avatar>
          <span style="margin-left: 10px;">管理员</span>
        </div>
      </el-header>
      
      <!-- 主内容区 -->
      <el-container>
        <!-- 侧边菜单 -->
        <el-aside width="200px" class="aside">
          <el-menu
            default-active="1"
            class="el-menu-vertical-demo"
            @select="handleMenuSelect"
          >
            <el-menu-item index="1">
              <el-icon><House /></el-icon>
              <span>首页</span>
            </el-menu-item>
            <el-menu-item index="2">
              <el-icon><User /></el-icon>
              <span>客户管理</span>
            </el-menu-item>
            <el-menu-item index="3">
              <el-icon><ShoppingCart /></el-icon>
              <span>订单管理</span>
            </el-menu-item>
            <el-menu-item index="4">  <!-- 新增字段配置菜单 -->
              <el-icon><Setting /></el-icon>
              <span>字段配置</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        
        <!-- 主内容 -->
        <el-main class="main-content">
          <div class="welcome-card">
            <el-card>
              <div slot="header">
                <span>欢迎使用动态字段管理系统</span>
              </div>
              <div class="welcome-content">
                <p>本系统支持动态配置业务字段，无需修改代码即可灵活扩展业务数据结构。</p>
                <p>请通过左侧菜单选择需要操作的功能模块：</p>
                <div class="module-links">
                  <el-button 
                    type="primary" 
                    icon="User" 
                    @click="goToCustomer"
                  >
                    客户管理
                  </el-button>
                  <el-button 
                    type="success" 
                    icon="ShoppingCart" 
                    @click="goToOrder"
                  >
                    订单管理
                  </el-button>
                  <!-- 新增字段配置快捷按钮 -->
                  <el-button  
                    type="warning" 
                    icon="Setting" 
                    @click="goToFieldConfig"
                  >
                    字段配置
                  </el-button>
                </div>
              </div>
            </el-card>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router'
import { House, User, ShoppingCart, Setting } from '@element-plus/icons-vue'

const router = useRouter()

// 处理菜单选择
const handleMenuSelect = (index) => {
  switch(index) {
    case '1':
      router.push('/')
      break
    case '2':
      router.push('/customer')
      break
    case '3':
      router.push('/order')
      break
    case '4':  // 新增字段配置菜单处理
      router.push('/field-config')
      break
  }
}

// 跳转到客户管理
const goToCustomer = () => {
  router.push('/customer')
}

// 跳转到订单管理
const goToOrder = () => {
  router.push('/order')
}

// 新增：跳转到字段配置
const goToFieldConfig = () => {
  router.push('/field-config')
}
</script>

<style scoped>
.home-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  background-color: #165DFF;
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
}

.logo {
  font-size: 18px;
  font-weight: bold;
}

.user-info {
  display: flex;
  align-items: center;
}

.aside {
  background-color: #f5f7fa;
  border-right: 1px solid #e4e7ed;
}

.main-content {
  background-color: #f5f7fa;
  padding: 20px;
}

.welcome-card {
  max-width: 800px;
  margin: 0 auto;
}

.welcome-content {
  font-size: 16px;
  line-height: 1.8;
}

.module-links {
  margin-top: 30px;
  display: flex;
  gap: 20px;
}
</style>
